package com.exam.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.mapper.StudentMapper;
import com.exam.pojo.Login;
import com.exam.pojo.Student;
import com.exam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public Student getStudent(Login login) {
        Student student = new Student();
        byte[] psd = login.getPassword().getBytes();
        String psdMd = DigestUtils.md5DigestAsHex(psd);
        student.setStudentId(login.getUsername()).setPwd(psdMd);
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>(student);

        Student student1 = studentMapper.selectOne(queryWrapper);
        return student1;
    }

    @Override
    public IPage<Student> findAll(Page<Student> studentPage) {
        return studentMapper.findAll(studentPage);
    }

    @Override
    public Student findStudentById(Integer studentId) {
        return studentMapper.findStudentById(studentId);
    }

    @Override
    public void deleteStudentById(Integer studentId) {
        studentMapper.deleteStudentById(studentId);
    }


    @Override
    public int updatePwd(Student student) {
       return studentMapper.updatePwd(student);
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public int addStudent(Student student) {
        return studentMapper.addStudent(student);
    }
}
